<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@ include file="/WEB-INF/ibnms/common/jsCommonVariables.jsp"%>
        <script type="text/javascript" src="<%=application.getContextPath()%>/njs/basd/My97DatePicker/WdatePicker.js"></script>

    </head>
<body>
<div class="form-wrapper">
    	<%--<div class="form-title">--%>
       		 <%--<span class="ttcorner"></span>--%>
             <%--<h3>--%>
                <%--<span class="text"></span>--%>
             <%--</h3>--%>
        <%--</div>--%>
        <form name="theForm" >
			<input type="hidden" name="news.DEPT_ID" value="${news.DEPT_ID}"/>
		</form>
        <div class="box-in">
            <table border="0" cellspacing="0" cellpadding="0" class="table-03">
                <tr>
                    <td class="monitor_bg1" height="13" align ="right" nowrap>
                    发布人：
                    <input  type="text" class="input-style1" name="news.NAME"/>
                    标题：
                    <input  type="text" class="input-style1" name="news.TITLE"/>
                    内容：
                    <input  type="text" class="input-style1" name="news.CONTENT"/>
                </td>
                </tr>
                <tr>
                    <td class="monitor_bg1" height="13" align ="right" nowrap>
                        发布时间：<input type="text" name="news.STARTTIME" value="${news.STARTTIME}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" class="Wdate" style="width:150px"/>
                        - <input type="text" name="news.ENDTIME" value="${news.ENDTIME}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" class="Wdate" style="width:150px"/>
                        <input type="button" class="btn-style02" id="btn-search" value="查询" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="block02">
      		<div class="title-style02">
                <input class="btn-style02" type="button" id="btn-add" value="增加">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-see" value="查看">&nbsp;&nbsp;
                <input class="btn-style02" type="button" id="btn-edit" value="修改">&nbsp;&nbsp;
                <input class="btn-style02" type="button" id="btn-del" value="删除">
            </div>
            <table id="gridTable">
			</table>
			<div id="gridPager">
       	</div>
        </div>
</div>
</body>
		<script type="text/javascript">

			$(function(){
				$("#gridTable").jqGrid({
					url: "newsList.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['ID','标题', '内容', '发送人', '接收部门','发布时间','失效时间','是否有效'],
                    colModel:[
                        {name:'ID',index:'ID',hidden:true},
						{name:'TITLE',index:'TITLE'},
						{name:'CONTENT',index:'CONTENT',formatter:function(v){
                            if(!v){
                                return '';
                            }
                            else if(v.length>40 && v.indexOf("\n")<0){
                                return v.substring(0,40)+" ...";
                            }
                            else if(v.indexOf("\n")>=0){
                                return v.split("\n")[0]+" ...";
                            }
                            return v;
                        }},
						{name:'NAME',index:'NAME',align:"center"},
						{name:'RCV_DEPT_NAME',index:'RCV_DEPT_NAME'},
                        {name:'PUBLISH_TIME',index:'PUBLISH_TIME',align:"center"},
                        {name:'FAILURE_TIME',index:'FAILURE_TIME',align:"center"},
                        {name:'NEWS_STATUS',index:'NEWS_STATUS',align:"center"}
                    ],
					viewrecords: true,
					rowNum: 50,
					rowList: [15,30,50],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true,
					beforeRequest:function(){
						var postData = {};
						$(":input[name^='news.']").each(function(){
							postData[$(this).attr("name")] = $(this).val();
						});
						$.extend($("#gridTable").getGridParam("postData"), postData);
					}
				});

			});


			$("#btn-search").click(function(){
				$("#gridTable").trigger("reloadGrid",[{page:1}]);
			});

			$("#btn-add").click(function(){
                window.showModalDialog("<s:url action="loadAddNews" />", "", "dialogWidth=800px,dialogHeight=600px");
                $("#gridTable").trigger("reloadGrid",[{page:1}]);
            });
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }
				if(confirm("确定删除记录?")){
					var ids = [];
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	ids.push(data.ID);
                    }

					$.ajax({
						type: "POST",
						async: false,
                        data:{ids:ids},
						url: "<s:url action="delNews" />",
						success: function(data){
                            $("#gridTable").trigger("reloadGrid",[{page:1}]);
						},
						error:function(xhr){
							show_error(xhr);
						}
					});
                }
			});
			$("#btn-see").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择记录!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
                        window.showModalDialog("<s:url action="loadAddNews" />?id="+data.ID+"&op=view&nowtime="+new Date(), "", "dialogWidth=800px,dialogHeight=600px");
                        $("#gridTable").trigger("reloadGrid",[{page:1}]);
                        break;
					default:
						alert("一次只能选择一条记录!");
				}
			});

            $("#btn-edit").click(function() {
                var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                switch (idArr.length) {
                    case 0:
                        alert("请先选择记录!");
                        break;
                    case 1:
                        var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
                        window.showModalDialog("<s:url action="loadAddNews" />?id="+data.ID+"&op=edit&nowtime="+new Date(), "", "dialogWidth=800px,dialogHeight=600px");
                        $("#gridTable").trigger("reloadGrid",[{page:1}]);
                        break;
                    default:
                        alert("一次只能选择一条记录!");
                }
            });
        </script>
</html>